//
//  CALayer+SWAdd.m
//  QZMJ
//
//  Created by 曾少伟 on 2016/12/17.
//  Copyright © 2016年 曾少伟. All rights reserved.
//

#import "CALayer+SWAdd.h"

@implementation CALayer (SWAdd)

- (void)setTransform3DRotationX:(CGFloat)transform3DRotationX {
    [self setTransform3DRotationX:transform3DRotationX anchorPoint:CGPointMake(0.5, 0)];
}

- (void)setTransform3DRotationY:(CGFloat)transform3DRotationY {
    [self setTransform3DRotationY:transform3DRotationY anchorPoint:CGPointMake(0.5, 0)];
}

- (void)setTransform3DRotationZ:(CGFloat)transform3DRotationZ {
    [self setTransform3DRotationZ:transform3DRotationZ anchorPoint:CGPointMake(0.5, 0)];
}

- (void)setTransform3DRotationX:(CGFloat)transform3DRotationX anchorPoint:(CGPoint)anchorPoint{
    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = - 1.0/500.0;
    CATransform3D transform1 = CATransform3DRotate(transform, transform3DRotationX, 0, 1, 0);
    NSValue *value = [NSValue valueWithCATransform3D:transform1];
    self.anchorPoint = anchorPoint;
    [self setValue: value forKeyPath:@"transform"];
}

- (void)setTransform3DRotationY:(CGFloat)transform3DRotationY anchorPoint:(CGPoint)anchorPoint{
    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = - 1.0/500.0;
    CATransform3D transform1 = CATransform3DRotate(transform, transform3DRotationY, 1, 0, 0);
    NSValue *value = [NSValue valueWithCATransform3D:transform1];
    self.anchorPoint = anchorPoint;
    [self setValue: value forKeyPath:@"transform"];
}

- (void)setTransform3DRotationZ:(CGFloat)transform3DRotationZ anchorPoint:(CGPoint)anchorPoint{
    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = - 1.0/500.0;
    CATransform3D transform1 = CATransform3DRotate(transform, transform3DRotationZ, 0, 0, 1);
    NSValue *value = [NSValue valueWithCATransform3D:transform1];
    self.anchorPoint = anchorPoint;
    [self setValue: value forKeyPath:@"transform"];
}


@end
